#define _CRT_SECURE_NO_WARNINGS 1

double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size) {
    int sum = (nums1Size + nums2Size);
    int mid = sum / 2;
    double ret = 0;
    double ret2 = 0;
    int i = 0;
    int t1 = 0;
    int t2 = 0;
    for (i = 0; i <= mid; i++)
    {
        if (t1 >= nums1Size)
        {
            ret2 = ret;
            ret = nums2[t2++];
        }
        else if (t2 >= nums2Size)
        {
            ret2 = ret;
            ret = nums1[t1++];
        }
        else if (nums1[t1] < nums2[t2])
        {
            ret2 = ret;
            ret = nums1[t1++];
        }
        else
        {
            ret2 = ret;
            ret = nums2[t2++];
        }
    }
    if (sum % 2 == 0)
    {
        return (ret2 + ret) / 2;
    }
    return ret;
}